Skip to content

Report explicit tail calls as unsupported instead of panicking - #5152

Merged
feliperodri merged 2 commits into
model-checking:mainfrom
mvanhorn:fix/5131-explicit-tail-call-unsupported
Nov 13, 2026
Merged

feliperodri merged 2 commits into
model-checking:mainfrom
mvanhorn:fix/5131-explicit-tail-call-unsupported

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Why

Verifying code that uses an explicit tail call (become) can crash the compiler with a “not implemented” panic instead of reporting an unsupported feature.

rustc_public has no TailCall terminator variant, so converting a body containing one reaches unimplemented!(). Kani loaded these bodies without checking for explicit tail calls first.

What changed

The diff checks internal MIR before body conversion during transformation, proof metadata generation, and autoharness processing, including instantiation search. It reports each explicit tail call in the body at its source span and aborts with an unsupported-feature diagnostic. It adds a diagnostic regression test and a verification case where the harness never calls the function containing become. It also documents explicit tail calls as unsupported.

Testing

Run locally on macOS with the pinned toolchain (nightly-2026-10-23):

  • cargo build-dev, cargo fmt --check and cargo clippy -p kani-compiler -p kani-driver -p kani_metadata --all-targets -- -D warnings pass.
  • cargo run -p compiletest -- --suite ui --mode expected explicit-tail-calls: 3 passed (ui/explicit-tail-calls/main.rs and the two new stubbing tests).
  • cargo run -p compiletest -- --suite kani --mode kani TailCall: 1 passed.
  • cargo run -p compiletest -- --suite script-based-pre --mode exec autoharness: 47 passed, including the new autoharness_explicit_tail_call, where tail_call is skipped and ok_fn is verified.
  • cargo run -p compiletest -- --suite expected --mode expected stub contract: 230 passed.
  • On 656f228, before this round, the two stubbing tests panic in rustc_public and the autoharness run aborts.

Fixes #5131

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

AI was used for assistance.

The diff checks internal MIR before body conversion during
transformation, proof metadata generation, and autoharness processing,
including instantiation search. It reports each explicit tail call in
the body at its source span and aborts with an unsupported-feature
diagnostic. It adds a diagnostic regression test and a verification case
where the harness never calls the function containing `become`. It also
documents explicit tail calls as unsupported.

Fixes model-checking#5131
@mvanhorn
mvanhorn requested review from a team as code owners November 11, 2026 09:04
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Nov 11, 2026
@feliperodri
feliperodri requested a balanced review from Copilot November 12, 2026 17:43
@feliperodri feliperodri self-assigned this Nov 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Stub validation can still panic on become because body conversions occur before the guard, leaving earlier conversions and body loaders unprotected for both concrete and generic stubs.

1 open issue
What changed in this PR

This PR addresses #5131 by checking for explicit tail calls (become) before MIR conversion, so Kani can report an unsupported-feature diagnostic instead of a compiler panic.

Changes:

  • Adds checks during transformation, proof metadata generation, and autoharness processing.
  • Adds diagnostic and unreachable-function regression cases.
  • Documents explicit tail calls as unsupported.
File Description
tests/​ui/​explicit-tail-calls/​main.rs Adds a reachable tail-call diagnostic case.
tests/​ui/​explicit-tail-calls/​expected Specifies the expected unsupported-feature error.
tests/​kani/​TailCall/​unreachable.rs Checks that an uncalled tail-call function does not affect verification.
kani-compiler/​src/​kani_middle/​transform/​mod.rs Checks for tail calls before transforming bodies.
kani-compiler/​src/​kani_middle/​mod.rs Adds the shared internal-MIR check and diagnostic.
kani-compiler/​src/​kani_middle/​metadata.rs Checks harness bodies before metadata conversion.
kani-compiler/​src/​kani_middle/​codegen_units.rs Adds checks to autoharness processing and instantiation search.
docs/​src/​rust-feature-support/​unstable.md Lists explicit tail calls as unsupported.

Review effort: Balanced

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, reporting become instead of panicking inside rustc_public is the right fix, and checking the internal MIR before conversion targets the actual failure. The two tests cover the reachable and unreachable cases. A few things before merge:

  1. Remaining panics. Several places still convert bodies before any guard. One is stub validation (stubbing/mod.rs:81-82, Copilot's thread), which I agree with. Others: the stub body in FnStubPass (transform/stubs.rs:148), and mined invariants under --constructor-args/--check-invariants (mined_invariants.rs:320 and :440, which load every inherent method of a type). Rather than "call this right before instance.body()", which is easy to miss in the next new caller, consider one helper such as checked_body(tcx, instance) -> Option<Body> that does both, and use it at every call site. Please add a stubbing regression as Copilot suggests.
  2. Autoharness aborts the whole run. automatic_harness_partition calls the check for every local function, so a single become anywhere in the crate stops autoharness, and no other function gets a verdict. #5119 fixed the same problem for uninhabited downcasts. Could such functions be skipped instead, with a reason like "explicit tail calls are not supported", as other ineligible functions are? Please add an autoharness test for it.
  3. PR description. The Testing section reads like a tool transcript ("the kani resolve_deferred_fn_slots change", "the transcript does not record its exit status"). Please say what you ran and what passed. CI covers the rest.

I added [F] Crash and [E] Unsupported Construct (from #5131).

Comment thread kani-compiler/src/kani_middle/mod.rs Resolved
@feliperodri feliperodri added [F] Crash Kani crashed [E] Unsupported Construct Add support to an unsupported construct labels Nov 12, 2026
@feliperodri feliperodri assigned mvanhorn and unassigned feliperodri Nov 12, 2026
…utoharness

Address review on model-checking#5152: rather than calling a guard before each
`instance.body()`, add helpers in `kani_middle` that check the internal MIR
for `TerminatorKind::TailCall` and then convert:

- `checked_body` / `checked_fn_def_body` report the unsupported diagnostic
  and abort. Used by `body_ref`, harness metadata, stub validation
  (`check_compatibility`), the stub body in `FnStubPass`, the autoharness
  transform, delayed-UB / points-to analysis and mutual-recursion checks.
- `has_explicit_tail_call` / `body_without_tail_calls` report nothing. Used
  where an unsupported body should just be ignored: autoharness
  eligibility, instantiation search, constructor inlining, invariant mining
  (`--constructor-args` / `--check-invariants`) and the diagnostic-only
  `kani::any` cycle check.

`ExternFnStubPass` now asks `FnDef::has_body` instead of converting the
body just to test for one.

Autoharness no longer aborts the run when one function uses `become`: it
is skipped with the new `AutoHarnessSkipReason::UnsupportedTailCall`
("Explicit tail calls are not supported"), and the other functions are
still verified.

Tests: stubbing regressions with `become` in the original and in the
replacement (both panicked in `rustc_public` before), and an autoharness
run where `tail_call` is skipped and `ok_fn` is verified (the whole run
aborted before).
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. Addressed in fa462b8:

  1. Remaining panics: added checked_body / checked_fn_def_body in kani_middle/mod.rs, which check the internal MIR for TailCall before converting and report the unsupported diagnostic. They now back body_ref, harness metadata, stub validation (check_compatibility), the stub body in FnStubPass, the autoharness transform, delayed-UB / points-to and the mutual-recursion checks. Where an unsupported body should just be ignored (autoharness eligibility, instantiation search, constructor inlining, invariant mining under --constructor-args / --check-invariants), body_without_tail_calls returns None without a diagnostic. ExternFnStubPass now uses FnDef::has_body instead of converting the body. Added stubbing regressions in tests/ui/explicit-tail-calls-stubbing/ with become in the original and in the replacement.
  2. Autoharness: functions with become are now skipped with AutoHarnessSkipReason::UnsupportedTailCall ("Explicit tail calls are not supported"), like other ineligible functions, so the rest of the crate still gets a verdict. Added tests/script-based-pre/autoharness_explicit_tail_call for this.
  3. Updated the Testing section of the description.

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mvanhorn, this round addresses everything from my last review. checked_body / checked_fn_def_body, with body_without_tail_calls for the heuristics, is a good split. Stub validation, FnStubPass, mined invariants and autoharness now all go through it, and the stubbing and autoharness tests cover the new paths.

I built fa462b8 and ran the new ui, kani and script-based-pre tests, plus the expected/kani stubbing suites; all pass.

One case is still open, and I'll track it in a follow-up issue rather than block this PR. Autoharness skips a function that contains become, but not one that calls such a function. With pub fn caller(x: u8) -> u8 { tail_call(x % 3) } in the same crate, the run aborts at the diagnostic and ok_fn gets no verdict. That's a proper error now, not the panic from #5131, but ideally only the harnesses that reach the become would fail. The experimental LLBC backend (mir_to_ullbc) also still loads bodies with instance.body() directly.

Optional: my earlier nit on internal_body_kind still applies. It's an identity mapping apart from Intrinsic → Item, so match … { InstanceKind::Intrinsic(d) => InstanceKind::Item(d), def => def } says that directly.

The red macos-14 jobs are a runner configuration issue, unrelated to this PR.

@feliperodri

Copy link
Copy Markdown
Member

Follow-up for the remaining cases: #5160.

@feliperodri
feliperodri added this pull request to the merge queue Nov 13, 2026
Merged via the queue into model-checking:main with commit 7f89576 Nov 13, 2026
23 of 26 checks passed
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for merging this, @feliperodri. Explicit tail calls (become) now get an unsupported-feature diagnostic instead of a compiler panic, and autoharness skips those functions rather than aborting the whole run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[E] Unsupported Construct Add support to an unsupported construct [F] Crash Kani crashed Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler panic on explicit tail calls (become)

3 participants